package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import dao.*;
import entity.*;

/**
 * Servlet implementation class ModifyThemeServlet
 */
@WebServlet("/ModifyThemeServlet")
public class ModifyThemeServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ModifyThemeServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");
		//response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out = response.getWriter();
		Theme theme = new Theme();
		theme.setTheme_id(Integer.parseInt(request.getParameter("user_id")));
		theme.setTheme_name(request.getParameter("user_name"));
		
		ThemeDAO.getInstance().update(theme);
		
		//TODO 提示修改成功 的信息
		//response.sendRedirect("result_information.jsp?");
		request.setAttribute("result_information","修改成功！" );
		request.setAttribute("return_page","ManageThemeServlet" );
		request.setAttribute("return_page_name","主题列表" );
		RequestDispatcher view = request.getRequestDispatcher("result_information.jsp?");
		view.forward(request, response);
	}

}
